package authority

import (
	"context"

	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"
	"mall/service/backend/rpc/backendclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type MenuAuthorityLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMenuAuthorityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MenuAuthorityLogic {
	return &MenuAuthorityLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MenuAuthorityLogic) MenuAuthority(req *types.MenuAuthorityInfo) (resp *types.BaseMsgResp, err error) {
	res, err := l.svcCtx.BackendRpc.RoleMenuAuthority(l.ctx, &backendclient.RoleMenuAuthorityReq{
		RoleId:  req.RoleId,
		MenuIds: req.MenuIds,
	})
	if err != nil {
		return nil, err
	}

	return &types.BaseMsgResp{
		Success: true,
		Msg:     l.svcCtx.Trans.Trans(l.ctx, res.Msg),
	}, nil
}
